package com.dajie.pt.service.utils;

import com.dajie.framework.cache.key.StringBasedKeyGenerator;
import com.dajie.framework.cache.redis.*;
import com.dajie.framework.cache.redis.impl.jedis.cluster.*;
import com.dajie.framework.cache.serializer.FastJsonStringSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.JedisPubSub;

import java.net.InetAddress;
import java.net.UnknownHostException;

import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;

/**
 * Created by yunbinan on 16-11-30.
 */
public class RedisServer {
    private static JedisClusterFactory jedisClusterFactory = new ConfigBaseJedisClusterFactory("PT_SEND_CENTER");
    private static JedisCluster jedisCluster = jedisClusterFactory.create();
    private static ListOperation<String, String> listOperation = new JedisClusterBasedListOperationImpl<String, String>(
            "Dashboard", // 名称，为了管理方便，名称业务自己定
            jedisCluster,// jedisCluster实例
            new StringBasedKeyGenerator(), // key生成器
            new FastJsonStringSerializer<String>() // value的序列化方式
    );
    private static MapOperation mapOperation = new JedisClusterBasedMapOperationImpl<String>(
            "SmsSender", // 名称，为了管理方便，名称业务自己定
            jedisCluster, // jedisCluster实例
            new StringBasedKeyGenerator() // key生成器
    );
    private static StringOperation<String, String> stringOperation = new JedisClusterBasedStringOperationImpl<String, String>("SmsSender", jedisCluster, new StringBasedKeyGenerator(), new FastJsonStringSerializer<String>());
    private static SetOperation<String, String> setOperation = new JedisClusterBasedSetOperationImpl<String, String>(
            "Dashboard", // 名称，为了管理方便，名称业务自己定
            jedisCluster,// jedisCluster实例
            new StringBasedKeyGenerator(), // key生成器
            new FastJsonStringSerializer<String>()// value的序列化方式
    );

    private static class RedisServerSingleton {
        private static RedisServer instance = new RedisServer();
    }

    public static RedisServer getInstance() {
        return RedisServerSingleton.instance;
    }

    public Long llen(String key) {
        return listOperation.lLen(key);
    }

    public String lpop(String key) {
        return listOperation.lPop(key);
    }

}
